package org.genew.squadra.xml.model.builder;

import java.lang.reflect.Method;
import java.util.Date;
import java.util.ArrayList;
import java.util.Iterator;

import org.genew.squadra.xml.model.MyForm;
import org.genew.squadra.xml.model.content.metadati.Contributor;
import org.genew.squadra.xml.model.content.metadati.Coverage;
import org.genew.squadra.xml.model.content.metadati.Creator;
import org.genew.squadra.xml.model.content.metadati.Data;
import org.genew.squadra.xml.model.content.metadati.Description;
import org.genew.squadra.xml.model.content.metadati.Format;
import org.genew.squadra.xml.model.content.metadati.Identifier;
import org.genew.squadra.xml.model.content.metadati.Language;
import org.genew.squadra.xml.model.content.metadati.Metadata;
import org.genew.squadra.xml.model.content.metadati.Publisher;
import org.genew.squadra.xml.model.content.metadati.Relation;
import org.genew.squadra.xml.model.content.metadati.Rights;
import org.genew.squadra.xml.model.content.metadati.Source;
import org.genew.squadra.xml.model.content.metadati.Subject;
import org.genew.squadra.xml.model.content.metadati.Title;
import org.genew.squadra.xml.model.content.metadati.Type;
import org.springframework.stereotype.Component;

@Component
public class MetadataBuilderFromForm {
	
	public static Metadata build(MyForm myform){
		
		/*Obbligatori*/
		Title t = new Title(myform.getTitle());
		Language l = new Language(myform.getLanguage());
		Identifier id = new Identifier(myform.getIdentifier());
		Metadata mtd = new Metadata(t,l,id);
		
		/*Opzionali*/
		if (myform.getContributor() != null) mtd.setContributor(new Contributor(myform.getContributor()));
		if (myform.getCoverage() != null) mtd.setCoverage(new Coverage(myform.getCoverage()));
		if (myform.getCreator() != null) mtd.setCreator(new Creator(myform.getCreator()));
		if (myform.getDate() != null) mtd.setDate(new Data(new Date()));
		if (myform.getPublisher() != null) mtd.setPublisher(new Publisher(myform.getPublisher()));
		if (myform.getFormat() != null) mtd.setFormat(new Format(myform.getFormat()));
		if (myform.getSource() != null) mtd.setSource(new Source(myform.getSource()));
		if (myform.getType() != null) mtd.setType(new Type(myform.getType()));
		if (myform.getSubject() != null) mtd.setSubject(new Subject(myform.getSubject()));
		if (myform.getRelation() != null) mtd.setRelation(new Relation(myform.getRelation()));
		if (myform.getRights() != null) mtd.setRights(new Rights(myform.getRights()));
		if (myform.getDescription() != null) mtd.setDescription(new Description(myform.getDescription()));
				
		System.out.println(myform.getNum());
		
		
		return mtd;
		
	}


}
